clc
close all
clear all
[er, pdr, sinr,er_edge] = textread('controller.txt','%d%f%f%f');
TXRX = importdata('link_txrx_status_with_adaptation.txt');
[m,n]=size(TXRX); % m=11699 n=126
sender_index = 65;receiver_index = 93;
%sender_index = 79;receiver_index = 78;
targetRxPowerDbm = CalcRxPower( CalcDistance(sender_index,receiver_index),2.6);
targetrxPowerW = realpow(10,targetRxPowerDbm/10)/1000;
K=targetrxPowerW./er_edge;
SINR=[];
temp_sinr = [];
for i=1:1:m
    NI = 4.01237e-13;
    for j = 1:1:n-1
        if TXRX(i,j) == 1
            rxPowerDbm = CalcRxPower( CalcDistance(j,receiver_index),2.6);
            rxPowerW = realpow(10, rxPowerDbm/10)/1000;
            NI = NI + rxPowerW;
        end
    end
    NI_Dbm = 10*log10(NI*1000);
    sinr0=targetRxPowerDbm - NI_Dbm;
    temp_sinr = [temp_sinr sinr0];
    NI=0;
    if TXRX(i,126) == 1
        [p k] = size(temp_sinr);
        SINR=[SINR sum(temp_sinr)/k];
    end
end
SINR=SINR';

figure;
plot(er,'r','Marker','+'); hold on;
plot(pdr*20,'black','Marker','*'); hold on;
plot(SINR); hold on;
plot(K); hold on;
xlabel('# of Controller Adaptations');
%ylabel('Probability', 'FontSize', 16);
%set(gca,'FontSize',60);
legend ('ER size', 'PDR \times 20', 'SINR', 'PRK model parameter K');
maximize ();
saveas(gcf,'single_link_controller_behavior.jpg');
saveas(gcf,'single_link_controller_behavior.fig');
saveas(gcf,single_link_controller_behavior.eps');
